package com.jixiantubu.adapter;

import image.SmartImageView;

import java.util.ArrayList;
import java.util.List;

import com.example.jixiantubu.R;
import com.jixiantubu.bean.Travelsbean;
import com.jixiantubu.util.EllipsizeText;
import com.jixiantubu.util.MyApplication;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class JinNang_YouJi_Find_Adapter extends BaseAdapter {
	Context context;// 上下文
	List<Travelsbean> list = new ArrayList<Travelsbean>();// 定义集合Travelsbean
	LayoutInflater mInflater;// 用来绑定布局
	ViewHolder viewHolder;// 初始化控件
	public JinNang_YouJi_Find_Adapter(Context context, List<Travelsbean> list) {
		super();
		this.context = context;
		this.list = list;
		mInflater = LayoutInflater.from(context);
	}
	
	
	
	public List<Travelsbean> getList() {
		return list;
	}



	public void setList(List<Travelsbean> list) {
		this.list = list;
	}



	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}


	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		viewHolder = new ViewHolder();
		if (arg1 == null) {// 如果界面是空的 （arg1是布局界面）
			// 使用mInflater绑定布局youji_item
			arg1 = mInflater.inflate(R.layout.jinnang_youji_find_item, null);
			//初始化标题
			viewHolder.t_title = (TextView) arg1
					.findViewById(R.id.jinnang_youji_find_title);
			//初始化用户头像
			viewHolder.headimg = (SmartImageView) arg1
					.findViewById(R.id.jinnang_youji_find_touxiang);
			//初始化用户昵称
			viewHolder.user_nickname = (TextView) arg1
					.findViewById(R.id.jinnang_youji_find_nickname);
			//初始化用户发表用户时间
			viewHolder.user_time = (TextView) arg1
					.findViewById(R.id.jinnang_youji_find_usertime);
			//初始化内容
			viewHolder.t_content = (EllipsizeText) arg1
					.findViewById(R.id.jinnang_youji_find_neirongjianjie);
			arg1.setTag(viewHolder);
		} else {// 如果界面不是空
			viewHolder = (ViewHolder) arg1.getTag();// 得到界面
		}String url = "http://" + MyApplication.getIP() + ":8080/Jinnang/img/"
				+ list.get(arg0).getUser_imgPath();
		Log.e("dajshdjaskhd", url);
		 viewHolder.headimg.setstyle("circle");
		viewHolder.headimg.setImageUrl(url, R.drawable.error, R.drawable.loding);// 得到用户头像
		// 得到用户昵称
		viewHolder.user_nickname.setText(list.get(arg0).getUser_nickname());
		// 得到用户的游记内容
		viewHolder.t_content.setText(list.get(arg0).getT_content());
		// 得到用户的上传游记时间
		viewHolder.user_time.setText(list.get(arg0).getT_time());
		// 得到用户的语句简介(游记标题)
		viewHolder.t_title.setText(list.get(arg0).getT_tittle());
			return arg1;
	}
	
	class ViewHolder {	
		TextView user_nickname, user_time, t_title;
		EllipsizeText t_content;
		image.SmartImageView headimg;
	}
	

}
